unit MyController;

interface

uses
  System.SysUtils, System.Classes, xsuperobject, MVC.BaseController,
  System.DateUtils, WechatApi, TextAskService;

type
  TMyController = class(TBaseController)
  public
    function getToken(): string;
    procedure CreateView; override;
  end;

implementation

{ TMyController }

procedure TMyController.CreateView;
begin
  inherited;
  with view do
  begin
    Plugin.Wechat.access_token := getToken;
  end;
end;

function TMyController.getToken: string;
var
  token, tmp: string;
begin
  with view do
  begin
    token := SessionGet('token');
    if token = '' then
    begin
      tmp := Plugin.Wechat.token('client_credential', 'wx14f38e8dd6c7bb7a', '334efa263f8c4e8f6ace4f447c32909f');
      token := SO(tmp).s['access_token'];
      SessionSet('token', token);
    end;
    Result := token;
  end;
end;

end.

